var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "f_name",
			name : "食品名称",
		},{
			colkey : "price",
			name : "价格",
		}, {
			colkey : "num",
			name : "订购数量"
		}, {
			colkey : "ordertime",
			name : "订购时间"
		}, {
			colkey : "id",
			name : "用户id"
		}],
		jsonUrl : rootPath + '/usermanage/selectOBByPage.shtml',
		checkbox : true,
		serNumber : true
	});
	$("#searchForm").click("click", function() {// 绑定查询按扭
		var searchParams = $("#fenye").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
	$("#hasorder").click("click", function() {// 绑定查询按扭
		$("#isbuy").val("0");
		var searchParams = $("#selectOB").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams,
			jsonUrl : rootPath + '/usermanage/selectOBByPage.shtml'
		});
	});
	$("#hasbuy").click("click", function() {// 绑定查询按扭
		$("#isbuy").val("1");
		var searchParams = $("#selectOB").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams,
			jsonUrl : rootPath + '/usermanage/selectOBByPage.shtml'
		});
	});
	
});


function ordertobuy() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择要购买的商品");
		return;
	}
	layer.confirm('是否购买？', function(index) {
		var url = rootPath + '/usermanage/orderToBuy.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('购买成功');
			grid.loadData();
		} else {
			layer.msg('购买失败,可能部分食品库存不够');
			grid.loadData();
		}
	});
}